package com.doupi.partner.service.impl;

import com.doupi.partner.dal.ProfitMapper;
import com.doupi.partner.model.Profit;
import com.doupi.partner.service.ProfitService;
import com.doupi.partner.util.Pagination;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProfitServiceImpl implements ProfitService {
	private final ProfitMapper profitMapper;

	@Autowired
	public ProfitServiceImpl(ProfitMapper profitMapper) {
		this.profitMapper = profitMapper;
	}

	public int deleteByPrimaryKey(Long id) {
		return profitMapper.deleteByPrimaryKey(id);
	}

	public int insert(Profit record) {
		return profitMapper.insert(record);
	}

	public Profit selectByPrimaryKey(Long id) {
		return profitMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(Profit record) {
		return profitMapper.updateByPrimaryKeySelective(record);
	}

	public int countProfit(Profit profit) {
		return profitMapper.countProfit(profit);
	}

	public List<Profit> queryProfits(Profit profit, RowBounds rowBounds) {
		return profitMapper.queryProfits(profit, rowBounds);
	}

	public List<Profit> selectProfitForUpdate(Profit profit) {
		return profitMapper.selectProfitForUpdate(profit);
	}

	public Profit selectProfitForUpdateByPrimaryKey(Long id) {
		return profitMapper.selectProfitForUpdateByPrimaryKey(id);
	}

	public Pagination<Profit, Profit> queryProfits(Pagination<Profit, Profit> pagination) {
		int count = countProfit(pagination.getParam());
		pagination.setTotalCount(count);
		if (count > 0) {
			pagination.setRecords(queryProfits(pagination.getParam(), new RowBounds(pagination.getOffset(), pagination.getLimit())));
		}
		return pagination;
	}

	@Override
	public int countProfitWithAnnotation(Profit profit) {
		return profitMapper.countProfitWithAnnotation(profit);
	}

	@Override
	public List<Profit> queryProfitWithAnnotation(Profit profit, RowBounds rowBounds) {
		return profitMapper.queryProfitWithAnnotation(profit, rowBounds);
	}

	@Override
	public Pagination<Profit, Profit> queryProfitWithAnnotation(Pagination<Profit, Profit> pagination) {
		int count = countProfitWithAnnotation(pagination.getParam());
		pagination.setTotalCount(count);
		if (count > 0) {
			pagination.setRecords(queryProfitWithAnnotation(pagination.getParam(), new RowBounds(pagination.getOffset(), pagination.getLimit())));
		}
		return pagination;
	}

	@Override
	public Map<String, Object> topStatistics(Long administratorId) {
		return profitMapper.topStatistics(administratorId);
	}

	@Override
	public List<Map<String, Object>> accumulateStatisticsGroupByHour(Long administratorId, Integer beginDay, Integer endDay) {
		return profitMapper.accumulateStatisticsGroupByHour(administratorId, beginDay, endDay);
	}

	@Override
	public List<Map<String, Object>> historyStatisticsGroupByHour(Long administratorId, Integer beginDay, Integer endDay) {
		return profitMapper.historyStatisticsGroupByHour(administratorId, beginDay, endDay);
	}

	@Override
	public List<Map<String, Object>> historyStatisticsGroupByDate(Long administratorId, Integer beginDay, Integer endDay) {
		return profitMapper.historyStatisticsGroupByDate(administratorId, beginDay, endDay);
	}

	@Override
	public List<Map<String, Object>> queryYesterdayProfitRank(Integer top) {
		return profitMapper.queryYesterdayProfitRank(top);
	}

}
